package com.jtcl.module.ob;


import lombok.Data;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;

import java.util.Observable;
import java.util.Observer;

/**
 * @author sjt
 * @since 2021-04-13 16:12
 */
@Slf4j
@Data
public class ReaderObserverImpl implements Observer {

    @NonNull
    private String name;

    private String article;

    @Override
    public void update(Observable o, Object arg) {
        // 更新文章
        updateArticle(o);
    }

    private void updateArticle(Observable o) {
        ObServableImpl javaStackObservable = (ObServableImpl) o;
        this.article = javaStackObservable.getArticle();
        log.info("我是读者：{}，文章已更新为：{}", this.name, this.article);
    }
}
